#include "StdAfx.h"
#include "deadZ80.h"
#include "opcodes.h"

int CDeadZ80::ExecuteOpcodeFDCB()
{
	unsigned char data = ReadMemory8(pc++);
	unsigned char opcode = ReadMemory8(pc++);
	unsigned short stmp,tmp16;
	unsigned char tmp;
	unsigned long ltmp;

	ltmp = (unsigned int)(unsigned short)((signed short)IY + (signed char)data);	\
	switch(opcode) {
		case 0x06: tmp = ReadMemory8(ltmp); RLC(tmp); WriteMemory8(ltmp,tmp); break; //rlc (ix+n)
		case 0x0E: tmp = ReadMemory8(ltmp); RRC(tmp); WriteMemory8(ltmp,tmp); break; //rrc (ix+n)
		case 0x16: tmp = ReadMemory8(ltmp); RL(tmp); WriteMemory8(ltmp,tmp); break; //rl (ix+n)
		case 0x1E: tmp = ReadMemory8(ltmp); RR(tmp); WriteMemory8(ltmp,tmp); break; //rr (ix+n)
		case 0x26: tmp = ReadMemory8(ltmp); SLA(tmp); WriteMemory8(ltmp,tmp); break; //sla (ix+n)
		case 0x2E: tmp = ReadMemory8(ltmp); SRA(tmp); WriteMemory8(ltmp,tmp); break; //sra (ix+n)
		case 0x36: tmp = ReadMemory8(ltmp); SLL(tmp); WriteMemory8(ltmp,tmp); break; //sla (ix+n)
		case 0x3E: tmp = ReadMemory8(ltmp); SRL(tmp); WriteMemory8(ltmp,tmp); break; //sra (ix+n)
		case 0x40:
		case 0x41:
		case 0x42:
		case 0x43:
		case 0x44:
		case 0x45:
		case 0x46:	//bit 0,(ix+n)
		case 0x47:	BIT_IDX(0);							break;
		case 0x48:
		case 0x49:
		case 0x4A:
		case 0x4B:
		case 0x4C:
		case 0x4D:
		case 0x4E:	//bit 1,(ix+n)
		case 0x4F:	BIT_IDX(1);							break;
		case 0x50:
		case 0x51:
		case 0x52:
		case 0x53:
		case 0x54:
		case 0x55:
		case 0x56:	//bit 2,(ix+n)
		case 0x57:	BIT_IDX(2);							break;
		case 0x58:
		case 0x59:
		case 0x5A:
		case 0x5B:
		case 0x5C:
		case 0x5D:
		case 0x5E:	//bit 3,(ix+n)
		case 0x5F:	BIT_IDX(3);							break;
		case 0x60:
		case 0x61:
		case 0x62:
		case 0x63:
		case 0x64:
		case 0x65:
		case 0x66:	//bit 4,(ix+n)
		case 0x67:	BIT_IDX(4);							break;
		case 0x68:
		case 0x69:
		case 0x6A:
		case 0x6B:
		case 0x6C:
		case 0x6D:
		case 0x6E:	//bit 5,(ix+n)
		case 0x6F:	BIT_IDX(5);							break;
		case 0x70:
		case 0x71:
		case 0x72:
		case 0x73:
		case 0x74:
		case 0x75:
		case 0x76:	//bit 6,(ix+n)
		case 0x77:	BIT_IDX(6);							break;
		case 0x78:
		case 0x79:
		case 0x7A:
		case 0x7B:
		case 0x7C:
		case 0x7D:
		case 0x7E:	//bit 7,(ix+n)
		case 0x7F:	BIT_IDX(7);							break;
		case 0x80:
		case 0x81:
		case 0x82:
		case 0x83:
		case 0x84:
		case 0x85:
		case 0x86:	//res 0,(ix+n)
		case 0x87:	RES_IDX(0);							break;
		case 0x88:
		case 0x89:
		case 0x8A:
		case 0x8B:
		case 0x8C:
		case 0x8D:
		case 0x8E:	//res 1,(ix+n)
		case 0x8F:	RES_IDX(1);							break;
		case 0x90:
		case 0x91:
		case 0x92:
		case 0x93:
		case 0x94:
		case 0x95:
		case 0x96:	//res 2,(ix+n)
		case 0x97:	RES_IDX(2);							break;
		case 0x98:
		case 0x99:
		case 0x9A:
		case 0x9B:
		case 0x9C:
		case 0x9D:
		case 0x9E:	//res 3,(ix+n)
		case 0x9F:	RES_IDX(3);							break;
		case 0xA0:
		case 0xA1:
		case 0xA2:
		case 0xA3:
		case 0xA4:
		case 0xA5:
		case 0xA6:	//res 4,(ix+n)
		case 0xA7:	RES_IDX(4);							break;
		case 0xA8:
		case 0xA9:
		case 0xAA:
		case 0xAB:
		case 0xAC:
		case 0xAD:
		case 0xAE:	//res 5,(ix+n)
		case 0xAF:	RES_IDX(5);							break;
		case 0xB0:
		case 0xB1:
		case 0xB2:
		case 0xB3:
		case 0xB4:
		case 0xB5:
		case 0xB6:	//res 6,(ix+n)
		case 0xB7:	RES_IDX(6);							break;
		case 0xB8:
		case 0xB9:
		case 0xBA:
		case 0xBB:
		case 0xBC:
		case 0xBD:
		case 0xBE:	//res 7,(ix+n)
		case 0xBF:	RES_IDX(7);							break;
		case 0xC0:
		case 0xC1:
		case 0xC2:
		case 0xC3:
		case 0xC4:
		case 0xC5:
		case 0xC6:	//set 0,(ix+n)
		case 0xC7:	SET_IDX(0);							break;
		case 0xC8:
		case 0xC9:
		case 0xCA:
		case 0xCB:
		case 0xCC:
		case 0xCD:
		case 0xCE:	//set 1,(ix+n)
		case 0xCF:	SET_IDX(1);							break;
		case 0xD0:
		case 0xD1:
		case 0xD2:
		case 0xD3:
		case 0xD4:
		case 0xD5:
		case 0xD6:	//set 2,(ix+n)
		case 0xD7:	SET_IDX(2);							break;
		case 0xD8:
		case 0xD9:
		case 0xDA:
		case 0xDB:
		case 0xDC:
		case 0xDD:
		case 0xDE:	//set 3,(ix+n)
		case 0xDF:	SET_IDX(3);							break;
		case 0xE0:
		case 0xE1:
		case 0xE2:
		case 0xE3:
		case 0xE4:
		case 0xE5:
		case 0xE6:	//set 4,(ix+n)
		case 0xE7:	SET_IDX(4);							break;
		case 0xE8:
		case 0xE9:
		case 0xEA:
		case 0xEB:
		case 0xEC:
		case 0xED:
		case 0xEE:	//set 5,(ix+n)
		case 0xEF:	SET_IDX(5);							break;
		case 0xF0:
		case 0xF1:
		case 0xF2:
		case 0xF3:
		case 0xF4:
		case 0xF5:
		case 0xF6:	//set 6,(ix+n)
		case 0xF7:	SET_IDX(6);							break;
		case 0xF8:
		case 0xF9:
		case 0xFA:
		case 0xFB:
		case 0xFC:
		case 0xFD:
		case 0xFE:	//set 7,(ix+n)
		case 0xFF:	SET_IDX(7);							break;

		default:
			message("bad DDCB opcode = $%02X\n",opcode);
			return(1);
	}
	return(0);
}

